<?php
	// verify that this is a product category page
		global $wp_query;
	// get the query object
		$cat = $wp_query->get_queried_object();
	// get the thumbnail id user the term_id
		$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); 
	// get the image URL
		$prodcatimage = wp_get_attachment_url( $thumbnail_id );
		
	// GET FEATURED PRODUCT ID #s FROM THE CUSTOM FIELDS
		$featuredproductoneid = get_field('catfeaturedproductone', 'product_cat_'.$category_ID.'');
		$featuredproducttwoid = get_field('catfeaturedproducttwo', 'product_cat_'.$category_ID.'');
		$featuredproductthreeid = get_field('catfeaturedproductthree', 'product_cat_'.$category_ID.'');
		$featuredproductfourid = get_field('catfeaturedproductfour', 'product_cat_'.$category_ID.'');
		
?>
        
        <?php include '/home/silicons/public_html/wp-content/themes/woostore/page-include-social-block.php'; ?>
	<h1 class="pagesubsectionheader" style="margin-bottom:0px;">Featured <?php woocommerce_page_title(); ?></h1>
        <div id="categoryfeaturedblock">
		<div id="categoryfeaturedblockimage">
			<img src="<?php echo $prodcatimage; ?>" alt="<?php echo $category_name; ?>" />
		</div>
		<div id="categoryfeaturedblockcontent">
		
			<!-- Display The 2 Product Layout If Called For -->
			<?php if (get_field('catfeaturedproductlayout', 'product_cat_'.$category_ID.'') == 2) { ?>
			
				<!-- FEATURED PRODUCT #1 -->
				<?php $featuredproduct = new wp_Query('post_type=product&p='.$featuredproductoneid.''); ?>
				<?php while($featuredproduct->have_posts()) : $featuredproduct->the_post(); ?>
					<?php
						$productsku = get_post_custom($post->ID);
						$showsku = $productsku['_sku'];
						foreach ( $showsku as $showsku );
						if (get_field('productFeaturedImage') != '') {
							$productimageurl = get_field('productFeaturedImage');
						} else {
							$productimageurl = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ));
							$productimageurl = $productimageurl[0];
						}
					?>
					<div class="categoryfeaturedproduct-two">
						<div class="categoryfeaturedproduct-twoprice">
							<p style="font-weight:bold;font-style:italic;color:#717470;"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
							
							<?php include '/home/silicons/public_html/wp-content/themes/woostore/woocommerce/single-product/price.php'; ?>
							<p><a href="<?php the_permalink(); ?>" class="button">View Details</a></p>
						</div>
						<div class="categoryfeaturedproduct-twoimage">
							<a href="<?php the_permalink(); ?>"><img src="<?php echo $productimageurl; ?>" alt="<?php the_title(); ?>" /></a>
						</div>
					</div>
				
				<?php endwhile; ?>
				<?php wp_reset_query() ; ?>
				
				<!-- FEATURED PRODUCT #2 -->
				<?php $featuredproducttwo = new wp_Query('post_type=product&p='.$featuredproducttwoid.''); ?>
				<?php while($featuredproducttwo->have_posts()) : $featuredproducttwo->the_post(); ?>
					<?php
						$productsku = get_post_custom($post->ID);
						$showsku = $productsku['_sku'];
						foreach ( $showsku as $showsku );
						if (get_field('productFeaturedImage') != '') {
							$productimageurl = get_field('productFeaturedImage');
						} else {
							$productimageurl = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ));
							$productimageurl = $productimageurl[0];
						}
					?>
					<div class="categoryfeaturedproduct-two">
						<div class="categoryfeaturedproduct-twoprice">
							<p style="font-weight:bold;font-style:italic;color:#717470;"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
							
							<?php include '/home/silicons/public_html/wp-content/themes/woostore/woocommerce/single-product/price.php'; ?>
							<p><a href="<?php the_permalink(); ?>" class="button">View Details</a></p>
						</div>
						<div class="categoryfeaturedproduct-twoimage">
							<a href="<?php the_permalink(); ?>"><img src="<?php echo $productimageurl; ?>" alt="<?php the_title(); ?>" /></a>
						</div>
					</div>
				
				<?php endwhile; ?>
				<?php wp_reset_query() ; ?>
			
			<!-- Display The 3 Product Layout If Called For -->
			<?php } elseif (get_field('catfeaturedproductlayout', 'product_cat_'.$category_ID.'') == 3) { ?>
			
				<!-- FEATURED PRODUCT #1 -->
				<?php $featuredproduct = new wp_Query('post_type=product&p='.$featuredproductoneid.''); ?>
				<?php while($featuredproduct->have_posts()) : $featuredproduct->the_post(); ?>
					<?php
						$productsku = get_post_custom($post->ID);
						$showsku = $productsku['_sku'];
						foreach ( $showsku as $showsku );
						if (get_field('productFeaturedImage') != '') {
							$productimageurl = get_field('productFeaturedImage');
						} else {
							$productimageurl = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ));
							$productimageurl = $productimageurl[0];
						}
					?>
					<div class="categoryfeaturedproduct-two">
						<div class="categoryfeaturedproduct-twoprice">
							<p style="font-weight:bold;font-style:italic;color:#717470;"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
							
							<?php include '/home/silicons/public_html/wp-content/themes/woostore/woocommerce/single-product/price.php'; ?>
							<p><a href="<?php the_permalink(); ?>" class="button">View Details</a></p>
						</div>
						<div class="categoryfeaturedproduct-twoimage">
							<a href="<?php the_permalink(); ?>"><img src="<?php echo $productimageurl; ?>" alt="<?php the_title(); ?>" /></a>
						</div>
					</div>
				
				<?php endwhile; ?>
				<?php wp_reset_query() ; ?>
				
				<!-- FEATURED PRODUCT #2 -->
				<?php $featuredproducttwo = new wp_Query('post_type=product&p='.$featuredproducttwoid.''); ?>
				<?php while($featuredproducttwo->have_posts()) : $featuredproducttwo->the_post(); ?>
					<?php
						$productsku = get_post_custom($post->ID);
						$showsku = $productsku['_sku'];
						foreach ( $showsku as $showsku );
						if (get_field('productFeaturedImage') != '') {
							$productimageurl = get_field('productFeaturedImage');
						} else {
							$productimageurl = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ));
							$productimageurl = $productimageurl[0];
						}
					?>
					<div class="categoryfeaturedproduct-four fourleft">
						<a href="<?php the_permalink(); ?>"><img src="<?php echo $productimageurl; ?>" alt="<?php the_title(); ?>" /></a>
						<span class="categoryfeaturedproduct-fourpricebanner">
							<?php include '/home/silicons/public_html/wp-content/themes/woostore/woocommerce/single-product/price.php'; ?>
						</span>
						<span class="categoryfeaturedproduct-fourbutton">
							<a class="button" href="<?php the_permalink(); ?>">View Details</a>
						</span>
					</div>
				
				<?php endwhile; ?>
				<?php wp_reset_query() ; ?>
				
				<!-- FEATURED PRODUCT #3 -->
				<?php $featuredproductthree = new wp_Query('post_type=product&p='.$featuredproductthreeid.''); ?>
				<?php while($featuredproductthree->have_posts()) : $featuredproductthree->the_post(); ?>
					<?php
						$productsku = get_post_custom($post->ID);
						$showsku = $productsku['_sku'];
						foreach ( $showsku as $showsku );
						if (get_field('productFeaturedImage') != '') {
							$productimageurl = get_field('productFeaturedImage');
						} else {
							$productimageurl = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ));
							$productimageurl = $productimageurl[0];
						}
					?>
					<div class="categoryfeaturedproduct-four fourright">
						<a href="<?php the_permalink(); ?>"><img src="<?php echo $productimageurl; ?>" alt="<?php the_title(); ?>" /></a>
						<span class="categoryfeaturedproduct-fourpricebanner">
							<?php include '/home/silicons/public_html/wp-content/themes/woostore/woocommerce/single-product/price.php'; ?>
						</span>
						<span class="categoryfeaturedproduct-fourbutton">
							<a class="button" href="<?php the_permalink(); ?>">View Details</a>
						</span>
					</div>
				
				<?php endwhile; ?>
				<?php wp_reset_query() ; ?>
			
			<!-- Display The 4 Product Layout If Called For -->
			<?php } elseif (get_field('catfeaturedproductlayout', 'product_cat_'.$category_ID.'') == 4) { ?>
			
				<!-- FEATURED PRODUCT #1 -->
				<?php $featuredproduct = new wp_Query('post_type=product&p='.$featuredproductoneid.''); ?>
				<?php while($featuredproduct->have_posts()) : $featuredproduct->the_post(); ?>
					<?php
						$productsku = get_post_custom($post->ID);
						$showsku = $productsku['_sku'];
						foreach ( $showsku as $showsku );
						if (get_field('productFeaturedImage') != '') {
							$productimageurl = get_field('productFeaturedImage');
						} else {
							$productimageurl = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ));
							$productimageurl = $productimageurl[0];
						}
					?>
					<div class="categoryfeaturedproduct-four fourleft">
						<a href="<?php the_permalink(); ?>"><img src="<?php echo $productimageurl; ?>" alt="<?php the_title(); ?>" /></a>
						<span class="categoryfeaturedproduct-fourpricebanner">
							<?php include '/home/silicons/public_html/wp-content/themes/woostore/woocommerce/single-product/price.php'; ?>
						</span>
						<span class="categoryfeaturedproduct-fourbutton">
							<a class="button" href="<?php the_permalink(); ?>">View Details</a>
						</span>
					</div>
				
				<?php endwhile; ?>
				<?php wp_reset_query() ; ?>
				
				<!-- FEATURED PRODUCT #3 -->
				<?php $featuredproducttwo = new wp_Query('post_type=product&p='.$featuredproducttwoid.''); ?>
				<?php while($featuredproducttwo->have_posts()) : $featuredproducttwo->the_post(); ?>
					<?php
						$productsku = get_post_custom($post->ID);
						$showsku = $productsku['_sku'];
						foreach ( $showsku as $showsku );
						if (get_field('productFeaturedImage') != '') {
							$productimageurl = get_field('productFeaturedImage');
						} else {
							$productimageurl = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ));
							$productimageurl = $productimageurl[0];
						}
					?>
					<div class="categoryfeaturedproduct-four fourright">
						<a href="<?php the_permalink(); ?>"><img src="<?php echo $productimageurl; ?>" alt="<?php the_title(); ?>" /></a>
						<span class="categoryfeaturedproduct-fourpricebanner">
							<?php include '/home/silicons/public_html/wp-content/themes/woostore/woocommerce/single-product/price.php'; ?>
						</span>
						<span class="categoryfeaturedproduct-fourbutton">
							<a class="button" href="<?php the_permalink(); ?>">View Details</a>
						</span>
					</div>
				
				<?php endwhile; ?>
				<?php wp_reset_query() ; ?>
				
				<!-- FEATURED PRODUCT #1 -->
				<?php $featuredproductthree = new wp_Query('post_type=product&p='.$featuredproductthreeid.''); ?>
				<?php while($featuredproductthree->have_posts()) : $featuredproductthree->the_post(); ?>
					<?php
						$productsku = get_post_custom($post->ID);
						$showsku = $productsku['_sku'];
						foreach ( $showsku as $showsku );
						if (get_field('productFeaturedImage') != '') {
							$productimageurl = get_field('productFeaturedImage');
						} else {
							$productimageurl = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ));
							$productimageurl = $productimageurl[0];
						}
					?>
					<div class="categoryfeaturedproduct-four fourleft">
						<a href="<?php the_permalink(); ?>"><img src="<?php echo $productimageurl; ?>" alt="<?php the_title(); ?>" /></a>
						<span class="categoryfeaturedproduct-fourpricebanner">
							<?php include '/home/silicons/public_html/wp-content/themes/woostore/woocommerce/single-product/price.php'; ?>
						</span>
						<span class="categoryfeaturedproduct-fourbutton">
							<a class="button" href="<?php the_permalink(); ?>">View Details</a>
						</span>
					</div>
				
				<?php endwhile; ?>
				<?php wp_reset_query() ; ?>
				
				<!-- FEATURED PRODUCT #4 -->
				<?php $featuredproductfour = new wp_Query('post_type=product&p='.$featuredproductfourid.''); ?>
				<?php while($featuredproductfour->have_posts()) : $featuredproductfour->the_post(); ?>
					<?php
						$productsku = get_post_custom($post->ID);
						$showsku = $productsku['_sku'];
						foreach ( $showsku as $showsku );
						if (get_field('productFeaturedImage') != '') {
							$productimageurl = get_field('productFeaturedImage');
						} else {
							$productimageurl = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ));
							$productimageurl = $productimageurl[0];
						}
					?>
					<div class="categoryfeaturedproduct-four fourright">
						<a href="<?php the_permalink(); ?>"><img src="<?php echo $productimageurl; ?>" alt="<?php the_title(); ?>" /></a>
						<span class="categoryfeaturedproduct-fourpricebanner">
							<?php include '/home/silicons/public_html/wp-content/themes/woostore/woocommerce/single-product/price.php'; ?>
						</span>
						<span class="categoryfeaturedproduct-fourbutton">
							<a class="button" href="<?php the_permalink(); ?>">View Details</a>
						</span>
					</div>
				
				<?php endwhile; ?>
				<?php wp_reset_query() ; ?>
			
			<!-- Display The 1 Product Layout If Called For, Or As Default -->
			<?php } else { ?>
			
				<?php $featuredproduct = new wp_Query('post_type=product&p='.$featuredproductoneid.''); ?>
				<?php while($featuredproduct->have_posts()) : $featuredproduct->the_post(); ?>
					<?php
						$productsku = get_post_custom($post->ID);
						$showsku = $productsku['_sku'];
						foreach ( $showsku as $showsku );
						if (get_field('productFeaturedImage') != '') {
							$productimageurl = get_field('productFeaturedImage');
						} else {
							$productimageurl = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ));
							$productimageurl = $productimageurl[0];
						}
					?>
					<div class="categoryfeaturedproduct">
						<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
						<?php if(has_sub_field('productfeatures')) { ?>
							<ul>
								<?php while(has_sub_field('productfeatures')) : ?>
									<li><?php the_field('productfeatureitem'); ?></li>
								<?php endwhile; ?>
							</ul>
						<?php } else { ?>
							<p><?php excerpt('25'); ?></p>
						<?php } ?>
						<div style="width:100%;height:0px;clear:both;margin-bottom:10px"></div>
						<div class="categoryfeaturedproductprice">
							
							<?php include '/home/silicons/public_html/wp-content/themes/woostore/woocommerce/single-product/price.php'; ?>
							<p><a href="<?php the_permalink(); ?>" class="button">View Details</a></p>
						</div>
						<div class="categoryfeaturedproductimage">
							<a href="<?php the_permalink(); ?>">
								<img src="<?php echo $productimageurl; ?>" alt="<?php the_title(); ?>" width="150" height="150" />
							</a>
						</div>
					</div><!-- .categoryfeaturedproduct -->
				
				<?php endwhile; ?>
				<?php wp_reset_query() ; ?>
			
			<?php } ?>
		
		</div><!-- #categoryfeaturedblockcontent -->
	</div><!-- #categoryfeaturedblock -->
	<?php if(has_sub_field('cattoppermenuitem')) { ?>
		<div class="categoryfeaturedblockmenu">
			<ul>
				<?php while(has_sub_field('cattoppermenuitem')) : ?>
					<li><a href="<?php the_sub_field('cattoppermenuitemlink'); ?>"><?php the_sub_field('cattoppermenuitemname'); ?></a></li>
				<?php endwhile; ?>
			</ul>
		</div>
	<?php } else { ?>
		<style>
			#categoryfeaturedblock { margin-bottom:20px; }
		</style>
	<?php } ?>